import {message} from 'antd';
import {formatMessage} from './intl';
export const newOrUpdateValidator = (data, details) => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.boardDate)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.boardDate',
            defaultMessage: '装船日期'
        }));
    if(!data || !data.boardPort)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.boardPort',
            defaultMessage: '装船港口'
        }));
    if(!data || !data.destinationPort)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.destinationPort',
            defaultMessage: '目的港口'
        }));
    if(!data || !data.carrierName)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.carrierName',
            defaultMessage: '承运人'
        }));
    if(!data || !data.planArriveTime)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.planArriveTime',
            defaultMessage: '预计到达时间'
        }));
    if(!data || details.length === 0)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.details',
            defaultMessage: '清单'
        }));

    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }

    return true;
};
